<?php
include '../db_params.php';

$center_lat='-33.385864';
$center_lng='-70.583389';
$radius=1000000;


$result = @mysql_query("SELECT users.uid as uid, users.name as nombre,otherlocations.lat as lat,otherlocations.lng as lng, ( 3959 * 1.609344 * acos( cos( radians('$center_lat') ) * cos( radians( lat ) ) * cos( radians( lng ) - radians('$center_lng') ) + sin( radians('$center_lat') ) * sin( radians( lat ) ) ) ) AS distance FROM locations as otherlocations, users as users WHERE (otherlocations.id=users.home_location) HAVING distance < '$radius' ORDER BY distance LIMIT 0 , 20");

$arr = array();

$i=0;
while($row = mysql_fetch_array($result))
  {
	$arr[$i]['name'] = utf8_decode ($row['nombre']);
	$arr[$i]['id'] = $row['uid'];
	$i=$i+1;
  }

mysql_close($con);

echo json_encode($arr);
?>